from rest_framework import mixins
from utils.response import SuccessResponse


class RetrieveModelMixin(mixins.RetrieveModelMixin):
    """
    Retrieve a model instance.
    """

    def retrieve(self, request, *args, **kwargs):
        res = super().retrieve(request, *args, **kwargs)
        return SuccessResponse(data=res.data, msg='查询成功！')


class ListModelMixin(mixins.ListModelMixin):
    def list(self, request, *args, **kwargs):
        res = super().list(request, *args, **kwargs)
        return SuccessResponse(data=res.data, msg='查询成功！')


class CreateModelMixin(mixins.CreateModelMixin):
    def create(self, request, *args, **kwargs):
        res = super().create(request, *args, **kwargs)
        return SuccessResponse(data=res.data, msg='创建成功！')


class DestroyModelMixin(mixins.DestroyModelMixin):
    def destroy(self, request, *args, **kwargs):
        res = super().destroy(request, *args, **kwargs)
        return SuccessResponse(data={'data': res.data}, msg='删除成功！')


class UpdateModelMixin(mixins.UpdateModelMixin):
    def update(self, request, *args, **kwargs):
        res = super().update(request, *args, **kwargs)
        return SuccessResponse(data={'data': res.data}, msg='修改成功！')
